package org.wattdepot.cli.command;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.wattdepot.cli.processor.CommandLineInterface;
import org.wattdepot.cli.processor.PowerCommand;

/**
 * Test for the Power command.
 * 
 * @author Kendyll Doi
 * @author Kimberly Heu
 * 
 */
public class TestPowerCommand extends CommandLineInterface {

  /**
   * Tests the Power methods.
   * 
   * @throws Exception If problems occur.
   */
  @Test
  public void testPowerCommand() throws Exception {

    List<String> commandList = new ArrayList<String>(); // List of commands

    commandList.add("power");
    commandList.add("generated");
    commandList.add("SIM_WAIAU_8");
    commandList.add("timestamp");
    commandList.add("2009-11-15T12:00:00.000-10:00");

    PowerCommand command = new PowerCommand(); // command

    // The result from executing the individual method
    String methodResult =
        WattPower.wattListPowerTime("generated", "SIM_WAIAU_8", "2009-11-15T12:00:00.000-10:00",
            client);
    // The result from executing corresponding command
    String commandResult = command.doCommand(commandList);

    // Ensure answer is correct
    assertTrue("Checking method result", methodResult.contains("8.8E7"));
    // Ensure both results are correct
    assertEquals("Checking method and command results are equal", methodResult, commandResult);
  }

  /**
   * Test that the input to the command is validated.
   * 
   * @throws Exception if problem occurs
   */
  @Test
  public void testInputValidation() throws Exception {

    List<String> commandList = new ArrayList<String>();
    commandList.add("power");
    commandList.add("generated");
    commandList.add("randomsource");
    commandList.add("timestamp");
    commandList.add("2009-11-15T12:00:00.000-10:00");

    PowerCommand command = new PowerCommand();
    String commandResult = command.doCommand(commandList);

    // Test for an incorrect source

    System.out.println(commandResult);
    assertTrue("Checking invalid source", commandResult.startsWith("No data found"));

    commandList.remove(2);
    commandList.add(2, "SIM_WAIAU_8");

    // Test for too few arguments
    commandList.remove(4);
    commandResult = command.doCommand(commandList);
    assertTrue("Checking invalid number of commands", commandResult.contains("Incorrect number"));

    commandList.add(4, "09-11-14");
    commandResult = command.doCommand(commandList);
    assertTrue("Checking invalid time input", commandResult.contains("Time argument"));

  }
}
